package com.best.intelligentTrolley

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageButton
import android.widget.TextView
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils

class SettingActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)

        val ibtn_return = findViewById<ImageButton>(R.id.ibtn_return)
        val tv_plasma_life_reset = findViewById<TextView>(R.id.tv_plasma_life_reset)
        val ibtn_low_left = findViewById<ImageButton>(R.id.ibtn_low_left)
        val et_low = findViewById<TextView>(R.id.et_low)
        val ibtn_low_right = findViewById<ImageButton>(R.id.ibtn_low_right)

        val ibtn_mid_left = findViewById<ImageButton>(R.id.ibtn_mid_left)
        val et_mid = findViewById<TextView>(R.id.et_mid)
        val ibtn_mid_right = findViewById<ImageButton>(R.id.ibtn_mid_right)

        val ibtn_high_left = findViewById<ImageButton>(R.id.ibtn_high_left)
        val et_high = findViewById<TextView>(R.id.et_high)
        val ibtn_high_right = findViewById<ImageButton>(R.id.ibtn_high_right)

        val tv_save = findViewById<TextView>(R.id.tv_save)

        et_low.setText(SPUtils.getInstance().getInt("speedLow",40).toString())
        et_mid.setText(SPUtils.getInstance().getInt("speedMid",60).toString())
        et_high.setText(SPUtils.getInstance().getInt("speedHigh",80).toString())

        ibtn_return.setOnClickListener {
            finish()
        }
        tv_plasma_life_reset.setOnClickListener {
            ConfirmDialog().show(supportFragmentManager,"")
        }

        ibtn_low_left.setOnClickListener {
            if(et_low?.text.toString().toInt()>0){
                et_low?.text = (et_low?.text.toString().toInt()-1).toString()
            }
        }
        ibtn_low_right.setOnClickListener {
            if(et_low?.text.toString().toInt()<100){
                et_low?.text = (et_low?.text.toString().toInt()+1).toString()
            }
        }
        ibtn_mid_left.setOnClickListener {
            if(et_mid?.text.toString().toInt()>0){
                et_mid?.text = (et_mid?.text.toString().toInt()-1).toString()
            }
        }
        ibtn_mid_right.setOnClickListener {
            if(et_mid?.text.toString().toInt()<100){
                et_mid?.text = (et_mid?.text.toString().toInt()+1).toString()
            }
        }
        ibtn_high_left.setOnClickListener {
            if(et_high?.text.toString().toInt()>0){
                et_high?.text = (et_high?.text.toString().toInt()-1).toString()
            }
        }
        ibtn_high_right.setOnClickListener {
            if(et_high?.text.toString().toInt()<100){
                et_high?.text = (et_high?.text.toString().toInt()+1).toString()
            }
        }
        tv_save.setOnClickListener {
            SPUtils.getInstance().put("speedLow",et_low?.text.toString().toInt())
            SPUtils.getInstance().put("speedMid",et_mid?.text.toString().toInt())
            SPUtils.getInstance().put("speedHigh",et_high?.text.toString().toInt())
            ToastUtils.showLong("保存成功！")
        }


    }
}